package com.example.test;



import sun.security.provider.MD5;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class Sign {
	private static final String KEY = "keysecret";
	
	public static void main(String[] args) {
		HashMap<String,String> params = new HashMap<>();
		params.put("name", "wang");
		params.put("age", "12");
		System.out.println(getSign(params));
	}
	
	public static String getSign(HashMap<String,String> params) {
		//利用TreeMap进行排序
		Map<String,String> sortedMap = new TreeMap<String,String>(params);
		//获取键值对
		Set<Map.Entry<String, String>> entrySet = sortedMap.entrySet();
		//遍历并且拼接
		StringBuilder stringA = new StringBuilder();
		for (Map.Entry<String, String> entry : entrySet) {
			String key = entry.getKey();
			if(key != null) {
				stringA.append(key).append("=").append(entry.getValue()).append("&");
			}
		}
		StringBuilder stringSignTemp = stringA.append(KEY);
		System.out.println(stringSignTemp.toString());
		MD5 md5 = new MD5();
		//String signValue = md5.getMD5ofStr(stringSignTemp.toString()).toUpperCase();
		//return signValue;
		return "";
	}
}
